<!DOCTYPE html>
<html lang="en">
<title>优惠券新增记录</title>
<#import "/layout/layout.html" as body/>
<@body.page>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="pull-left">优惠券新增记录列表</h5>
                </div>
                <div class="ibox-content">

                    <div class="table-responsive">
                        <form class="form-inline" role="form">
                            <div class="form-group margin-left">
                                <label for="id">券ID：</label>
                                <input class="form-control" id="id" type="text" placeholder="请输入券ID"/>
                            </div>
                            <button id="search" type="button" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                        </form>
                        <hr style="width: 100%">
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>券ID</th>
                                <th>券名</th>
                                <th>创建人</th>
                                <th>验证人</th>
                                <th>新增时间</th>
                            </tr>
                            </thead>
                            <tbody id="couponCheckList">
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="ibox-content overflow">
                    <div class="col-sm-12 padding-left-0">
                        <h4 class="pull-left">合计：<span id="couponCheckCount">0</span>条新增记录</h4>
                        <div id="copot-page" class="pull-right"></div>
                    </div>
                    <button type="button" id="go_back_list" class="btn btn-primary pull-left">返回列表</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    //返回列表
    $('#go_back_list').click(function () {
        window.location = "${baseUrl}system/coupon/to_list";
    });
    //搜索
    $("#search").click(function () {
        coursePage(1)
    });

    $(document).ready(function () {

        Date.prototype.pattern = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            var week = {
                "0": "/u65e5",
                "1": "/u4e00",
                "2": "/u4e8c",
                "3": "/u4e09",
                "4": "/u56db",
                "5": "/u4e94",
                "6": "/u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            var str = fmt.lastIndexOf("N");
            if (str != -1) {
                return "";
            }

            return fmt;
        }

        coursePage(1);
    });

    function coursePage(currentIndex) {
        var param = {
            "pageIndex": currentIndex,
            "pageSize": 10,
            "id": $("#id").val()
        };

        $.post("${baseUrl}system/coupon/add_list", param, function (result) {

            //分页
            new Page({
                parent: $("#copot-page"),
                nowPage: currentIndex,
                pageSize: 10,
                totalCount: result.couponCheckCount,
                setting: {
                    defaultPage: 5,//默认显示可点击分页的个数
                    firstPageText: "首页",
                    prevPageText: "上一页",
                    nextPageText: "下一页",
                    lastPageText: "尾页"
                },
                callback: function (nowPage, totalPage) {
                    coursePage(nowPage);
                }
            });

            $("#couponCheckCount").text(result.couponCheckCount);
//            <th>券ID</th>
//            <th>券名</th>
//            <th>创建人</th>
//            <th>验证人</th>
//            <th>新增时间</th>
            var html = "";
            var checkTime = null;

            $.each(result.couponCheckList, function (i, data) {

                if (data.checkTime) {
                    checkTime = new Date(data.checkTime).pattern("yyyy.MM.dd HH:mm");
                } else {
                    checkTime = "无数据/数据异常";
                }

                html += "<tr><td>" + data.id + "</td>";
                html += "<td>" + data.couponName + "</td>";
                html += "<td>" + data.createdBy + "</td>";
                html += "<td>" + data.checkName + "</td>";
                html += "<td>" + checkTime + "</td>";

                html += "</tr>";
            });
            $("#couponCheckList").html(html);

        });


    }
</script>
</@body.page>
</html>